package com.ruan.controller;

import com.ruan.entity.ResponseResult;
import com.ruan.entity.User;
import com.ruan.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @ClassName:LoginController
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/7/11 16:48
 **/
@RestController
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("/user/login")
    public ResponseResult login(User user, String verifyCode,HttpSession session){
        if(!verifyCode.equalsIgnoreCase((String) session.getAttribute("verifyCode"))){
            return new ResponseResult(100,"验证码错误");
        }
        return loginService.login(user,verifyCode);
    }

    @RequestMapping("/user/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }
}
